package com.stone.framework.core.context;

import java.util.Optional;

public class TokenContext {

	private final ThreadLocal<String> threadLocal = new ThreadLocal<>();

	public Optional<String> get() {
		return Optional.ofNullable(threadLocal.get());
	}

	public void set(String token) {
		threadLocal.set(token);
	}

	public void remove() {
		threadLocal.remove();
	}

	public static TokenContext build() {
		return SingletonHandler.SINGLETON;
	}

	private static class SingletonHandler {
		private static final TokenContext SINGLETON = new TokenContext();
	}

	private TokenContext() {

	}

}
